package plan;

import algorithm.AlgFactory;
import control.CtrlEngine;
import control.ExeCtx;
import control.PerfEvaluator;
import control.RelbEvaluator;
import control.SAModifier;
import control.MIC.MICCtrlEngine;
import foundation.fileUtil.FileNameUtil;
import foundation.fileUtil.PropFileUtil;

public class InitiExeCtx {
	String prjBasePath = FileNameUtil.getPrjPath();// 项目基路径

	public ExeCtx getInitCtx(String caseName, String prefix, String algName) {
		ExeCtx exeCtx = null;
		String srcPath = prjBasePath + "demo/" + caseName + "/runFiles/initialModel/";
		String runBasePath = prjBasePath + "demo/" + caseName + "/runFiles/resultFiles/";
		String algCfgFileName = prjBasePath + "demo/" + caseName + "/cfgFiles/" + algName + "Conf.properties";

		exeCtx = new ExeCtx(srcPath, runBasePath, prefix, algCfgFileName);

		return exeCtx;
	}


	public AlgFactory getAlgFactory(String caseName, String algName) {
		AlgFactory algFactory = null;
		String algFacCfgFileName = prjBasePath + "demo/" + caseName + "/cfgFiles/AlgFactoryCfg.properties";
		PropFileUtil proFileHelper = PropFileUtil.getInstance(algFacCfgFileName);
		String factoryClsNm = proFileHelper.getParameterValue(algName);
		try {
			Class<?> clzz = Class.forName(factoryClsNm);
			algFactory = (AlgFactory) clzz.newInstance();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return algFactory;
	}

	public CtrlEngine getCtrlEngine(String caseName, String prefix, String algName) {
		CtrlEngine ctrlEng = null;
		ExeCtx exeCtx = getInitCtx(caseName, prefix, algName);
		SAModifier saModifier = new SAModifier(exeCtx);
		PerfEvaluator perfEvaluator = new PerfEvaluator(exeCtx);
		RelbEvaluator relbEvaluator = new RelbEvaluator(exeCtx);
		ctrlEng = new MICCtrlEngine(exeCtx,saModifier,perfEvaluator,relbEvaluator);
		return ctrlEng;
	}
}
